package com.du.cloud.oauth.mapper;

import com.du.cloud.oauth.model.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Desc:
 * Author: dushuang
 * Date 2020/1/6 11:53
 */
public interface UserMapper {
    @Select("SELECT * FROM sys_user WHERE login_name=#{username}")
    User getUserByName(String username);

    @Select({"SELECT sru.rule_code",
            "FROM sys_user u",
            "LEFT JOIN sys_user_role su ON su.user_id = u.id",
            "LEFT JOIN sys_role sr ON sr.id = su.role_id",
            "LEFT JOIN sys_role_rule srr ON srr.role_id = sr.id",
            "LEFT JOIN sys_rule sru ON sru.id = srr.rule_id",
            "WHERE u.id = #{userId}"})
    List<String> getUserAuthorization(Long userId);

    @Select("SELECT s.* FROM sys_user_client uc LEFT JOIN sys_user s ON s.id = uc.user_id WHERE uc.client_id=#{clientId}")
    User getUserByClientId(String clientId);
}
